package com.log4jviewer.ui.preferences.filters;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableColumn;

/**
 * Class provides common fields and methods for creating filter's table and filter rule's table.
 * 
 * @author <a href="mailto:rd.ryly@gmail.com">Ruslan Diachenko</a>
 */
public abstract class AbstractFilterSettings {

    protected static final String ADD_BUTTON_NAME = "Add";
    protected static final String REMOVE_BUTTON_NAME = "Remove";

    protected abstract void createTableViewer(final Composite composite);

    protected abstract void createColumns();

    protected abstract void createButtons(final Composite composite);

    protected abstract TableViewer getTableViewer();

    protected void buildFilterControls(final Composite composite) {
        createTableViewer(composite);
        createButtons(composite);
    }

    protected TableViewerColumn createSingleColumn(final TableViewer tableViewer,
            final String columnTitle,
            final int columnWidth) {
        TableViewerColumn viewerColumn = new TableViewerColumn(tableViewer, SWT.NULL);
        TableColumn column = viewerColumn.getColumn();
        column.setText(columnTitle);
        column.setWidth(columnWidth);
        return viewerColumn;
    }

    protected Button createSingleButton(final Composite composite, final String buttonName) {
        Button button = new Button(composite, SWT.PUSH);
        button.setText(buttonName);
        GridData gridData = new GridData(SWT.NONE);
        gridData.widthHint = 90;
        button.setLayoutData(gridData);
        return button;
    }
}
